package com.mioto.ld.module.device.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.mioto.ld.communication.mqtt.MqttHelper;
import com.mioto.ld.module.device.model.*;
import com.mioto.ld.utils.BaseUtil;
import org.springframework.stereotype.Service;

import com.mioto.ld.module.device.dao.DeviceAlertLogDao;
import com.mioto.ld.module.device.service.IDeviceAlertLogService;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 *
 * @author mioto
 * @date 2024-05-15 16:13:50
 */
@Service("deviceAlertLogService")
public class DeviceAlertLogServiceImpl implements IDeviceAlertLogService{

    @Resource
    private DeviceAlertLogDao deviceAlertLogDao;

    @Override
    public List<DeviceAlertLog> findList(DeviceAlertLog deviceAlertLog) {
        return deviceAlertLogDao.findList(deviceAlertLog);
    }

    @Override
    public int insert(DeviceAlertLog deviceAlertLog) {
        return deviceAlertLogDao.insertIgnoreNull(deviceAlertLog);
    }

    @Override
    public int update(DeviceAlertLog deviceAlertLog) {
        return deviceAlertLogDao.update(deviceAlertLog);
    }

    @Override
    public int updateIgnoreNull(DeviceAlertLog deviceAlertLog) {
        return deviceAlertLogDao.updateIgnoreNull(deviceAlertLog);
    }

    @Override
    public DeviceAlertLog findByColumn(String column, Object value) {
        return deviceAlertLogDao.findByColumn(column,value);
    }

    @Override
    public int deleteByColumn(String column, Object value) {
        return deviceAlertLogDao.deleteByColumn(column,value);
    }

    @Override
    public int batchDelete(Integer[] ids) {
        return deviceAlertLogDao.batchDelete(ids);
    }

    @Override
    public List<DeviceAlertLogPagerVO> findPager(Integer deviceId, String startTime, String endTime) {
        return deviceAlertLogDao.findPager(deviceId,startTime,endTime,BaseUtil.buildUserFilterCondition());
    }

    @Override
    public DeviceAlertLog findLastLevelAlert(int alertId, int deviceId) {
        return deviceAlertLogDao.findLastLevelAlert(alertId,deviceId);
    }

    @Override
    public int updateRecoveryData(Integer deviceId, Set<Integer> alertIds, Date reportTime, String jsonStr) {
        return deviceAlertLogDao.updateRecoveryData(deviceId,alertIds,reportTime,jsonStr);
    }

    @Override
    public List<DeviceAlertLogAppPagerVO> findAppPager(String alertType,Integer[] deviceIds) {
        List<DeviceAlertLogAppPagerVO> list =  deviceAlertLogDao.findAppPager(BaseUtil.buildUserFilterCondition(),alertType,deviceIds);
        /*if (CollUtil.isNotEmpty(list)){
            for (DeviceAlertLogAppPagerVO deviceAlertLogAppPagerVO : list) {
                if (MqttHelper.containsSn(deviceAlertLogAppPagerVO.getSn())){
                    deviceAlertLogAppPagerVO.setOnlineStatus(DeviceStatus.ONLINE);
                }
            }
        }*/

        return list;
    }

}